package com.example.utils;

//import com.aliyun.auth.credentials.Credential;
//import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
//import com.aliyun.core.http.HttpClient;
//import com.aliyun.core.http.HttpMethod;
//import com.aliyun.core.http.ProxyOptions;
//import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
//import com.aliyun.sdk.service.dysmsapi20170525.models.*;
//import com.aliyun.sdk.service.dysmsapi20170525.*;
//import com.google.gson.Gson;
//import darabonba.core.RequestConfiguration;
//import darabonba.core.client.ClientOverrideConfiguration;
//import darabonba.core.utils.CommonUtil;
//import darabonba.core.TeaPair;
//import java.net.InetSocketAddress;
//import java.time.Duration;
//import java.util.*;
//import java.util.concurrent.CompletableFuture;

import com.aliyun.tea.*;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.dysmsapi20170525.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;
import com.aliyun.teautil.*;
import com.aliyun.teautil.models.*;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AliSmsUtill {

    /**
     * 使用AK&SK初始化账号Client
     *
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static Client client;

    static {
        Config config = new Config()
                // 必填，您的 AccessKey
                .setAccessKeyId("LTAI5tKMso3YGsYwUVPXvwGk")
                // 必填，您的 AccessKey Secret
                .setAccessKeySecret("0yOqvVjP2QysfI1T1FmHYajFa0gE9A");
        // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
        config.endpoint = "dysmsapi.aliyuncs.com";
        try {
            client = new Client(config);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /*
    * code:验证码
    * phone:手机号
    * */
    public static int sendSmsCode(String phone, String code) {
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setSignName("杨胜法的博客")
                .setTemplateCode("SMS_463681806")
                .setPhoneNumbers(phone)

                .setTemplateParam("{\"code\":" + code + "}");
        RuntimeOptions runtime = new RuntimeOptions();
        try {
            // 复制代码运行请自行打印 API 的返回值
            SendSmsResponse response = client.sendSmsWithOptions(sendSmsRequest, runtime);
            return response.getStatusCode();
        } catch (Exception e) {

        }
        return -1;
    }
}


